package com.eastfair.security.config;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.security.apiconditioncore.RequestMappingHandlerMappingCore;
import com.eastfair.security.resolver.ContextArgumentResolver;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

import java.util.Arrays;
import java.util.List;

/**
 * 公共配置类, 一些公共工具配置
 *
 * @author ligang
 * @date 2018/8/25
 */

//@Configuration
@AllArgsConstructor
public class LoginArgResolverConfig implements WebMvcConfigurer {


    /**
     * Token参数解析
     *
     * @param argumentResolvers 解析类
     */
    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(new ContextArgumentResolver());

    }


//    @Bean
//    public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
//        MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
//        ObjectMapper mapper = new ObjectMapper();
//        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//
//        SimpleModule module = new SimpleModule();
//        module.addDeserializer(IPage.class, new IPageDeserializer(IPage.class));
//        mapper.registerModule(module);
//
//        converter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON,MediaType.APPLICATION_JSON_UTF8,MediaType.APPLICATION_OCTET_STREAM));
//        converter.setObjectMapper(mapper);
//
//        return converter;
//    }





//    /**
//     * Token参数解析
//     *
//     * @param argumentResolvers 解析类
//     */
//    @Override
//    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
//        argumentResolvers.add(new ContextArgumentResolver());
//        super.addArgumentResolvers(argumentResolvers);
//    }
//
//
//    @Override
//    public RequestMappingHandlerMapping createRequestMappingHandlerMapping() {
//        return new RequestMappingHandlerMappingCore();
//    }
}
